package com.wyg.lambda.methodref.staticref;

import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * 一、静态方法引用示例
 *
 * 如果函数式接口的实现恰好可以通过调用一个静态方法来实现，那么久可以使用静态方法引用。
 *
 * 方法引用-表达式：
 *          类名::staticMethod   【仅仅表示引用，所以不需要staticMethod方法名后面加()】
 *
 * 对应普通Lambda-表达式：
 *          (args) -> 类名.staticMethod(args)
 *
 * @ClassName: StaticRef
 * @Auther: WangYG
 * @Date: 2020-02-21 18:42:53
 * @Version: 1.0
 */
public class StaticRef {


    /**
     * 功能描述: 演示简单的Lambda表示式-静态方法引用示例-输出参数演示
     * @methodName: one
     * @params: []
     * @return: void
     * @exception:
     * @auther: WangYG
     * @date: 2020-02-21 18:54:41
     */
    public void one(){

        //1.普通的Lambda表达式
        Supplier<String> s1 = () -> StaticRef.getName();
        System.out.println("this is StaticRef one() s1 : " + s1.get());
        Supplier<String> f1 = () -> Fun.put();
        System.out.println("StaticRef->Fun.put() lambda f1 : " + f1.get());

        //2.Lambda表达式-静态方法引用-示例
        Supplier<String> s2 = StaticRef::getName;
        System.out.println("this is StaticRef one() lambda-static-reference s2 : " + s2.get());

        Supplier<String> f2 = Fun::put;
        System.out.println("StaticRef->Fun.put() lambda-static-reference f1 : " + f2.get());
    }

    /**
     * 功能描述: 演示简单的Lambda表示式-静态方法引用示例-输入参数演示
     * @methodName: tow
     * @params: []
     * @return: void
     * @exception:
     * @auther: WangYG
     * @date: 2020-02-21 19:10:43
     */
    public void tow(){
        //1.普通Lambda表达式方法
        Consumer<String> c1 = (String name) -> StaticRef.sayName(name);
        System.out.print("this is StaticRef tow() c1 : ");
        c1.accept("张三");
        //2.Lambda表达式-静态方法引用-示例
        Consumer<String> c2 = StaticRef::sayName;
        System.out.print("this is StaticRef lambda-static-reference tow() c2 : ");
        c2.accept("李四");

    }

    /**
     * 功能描述: 演示简单的Lambda表示式-静态方法引用示例-一个输入参数 和 一个返回值演示
     * @methodName: three
     * @params: []
     * @return: void
     * @exception:
     * @auther: WangYG
     * @date: 2020-02-21 19:17:31
     */
    public void three(){
        //1.普通Lambda表达式方法
        Function<String,String> f0 = name -> name.toUpperCase();
        System.out.println("this is StaticRef three() f0 : " + f0.apply("lambda"));

        Function<String, String> f1 = (String code) -> StaticRef.toUpperCase(code);
        System.out.println("this is StaticRef three() f1 : " + f1.apply("abcde"));

        //2.Lambda表达式-静态方法引用-示例
        Function<String,String> f2 = StaticRef::toUpperCase;
        System.out.println("this is StaticRef lambda-static-reference tow() c2 : " + f2.apply("edcba"));

    }

    /**
     * 功能描述: 演示简单的Lambda表示式-静态方法引用示例-两个输入参数 和 一个返回值演示
     * @methodName: four
     * @params: []
     * @return: void
     * @exception:
     * @auther: WangYG
     * @date: 2020-02-21 19:26:17
     */
    public void four(){
        //1.普通Lambda表达式方法
        BiFunction<String,String,Integer> bi1 = (code1,code2) -> code1.length() + code2.length();
        BiFunction<String, String, Integer> bi2 = (code1, code2) -> StaticRef.countLength(code1, code2);
        System.out.println("this is StaticRef four() bi1 : " + bi1.apply("abc","efg"));
        System.out.println("this is StaticRef four() bi2 : " + bi2.apply("abcdd","efgaa"));

        //2.Lambda表达式-静态方法引用-示例
        BiFunction<String,String,Integer> bi3 = StaticRef::countLength;
        System.out.println("this is StaticRef lambda-static-reference four() bi3 : " + bi3.apply("lambda","staticref"));
    }


    public static String getName(){
        return "静态方法引用示例！";
    }

    public static void sayName(String name){
        System.out.println("your enter the name is ："+name);
    }

    public static String toUpperCase(String code){
        return code.toUpperCase();
    }

    public static Integer countLength(String code1,String code2){
        return code1.length() + code2.length();
    }

}

class Fun{
    public static String put(){
        return "this is Class Fun->put();";
    }
}
